lib/repo: Add mode and tombstone config options to the summary file
authorPhilip Withnall <withnall@endlessm.com>
Mon, 10 Aug 2020 11:05:06 +0000 (12:05 +0100)
committerPhilip Withnall <pwithnall@endlessos.org>
Thu, 1 Oct 2020 10:06:56 +0000 (11:06 +0100)
Currently, they are set in the `config` file and cause that to be
downloaded on every pull. Given that the client is already pulling the
`summary` file, it makes sense to avoid an additional network round trip
and cache those options in the `summary` file.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Helps: #2165

src/libostree/ostree-repo-private.h
src/libostree/ostree-repo.c
src/ostree/ot-dump.c
tests/test-summary-view.sh

index 8c1f5071030cbdb8d6ad97403b9311675727a2e4..a48feca4076f999ee1af19a717a1e03b167fe6c1 100644 (file)
@@ -55,6 +55,8 @@ G_BEGIN_DECLS
 #define OSTREE_SUMMARY_EXPIRES "ostree.summary.expires"
 #define OSTREE_SUMMARY_COLLECTION_ID "ostree.summary.collection-id"
 #define OSTREE_SUMMARY_COLLECTION_MAP "ostree.summary.collection-map"
+#define OSTREE_SUMMARY_MODE "ostree.summary.mode"
+#define OSTREE_SUMMARY_TOMBSTONE_COMMITS "ostree.summary.tombstone-commits"
 
 #define _OSTREE_PAYLOAD_LINK_PREFIX "../"
 #define _OSTREE_PAYLOAD_LINK_PREFIX_LEN (sizeof (_OSTREE_PAYLOAD_LINK_PREFIX) - 1)
index 4283f68ed6282b1bc933628ef95f6412fc09eedc..ba3e877f4f22eadfed49b1c811942f27992fd6ba 100644 (file)
@@ -5816,6 +5816,24 @@ ostree_repo_regenerate_summary (OstreeRepo     *self,
                                  g_variant_new_uint64 (GUINT64_TO_BE (g_get_real_time () / G_USEC_PER_SEC)));
   }
 
+  {
+    g_autofree char *remote_mode_str = NULL;
+    if (!ot_keyfile_get_value_with_default (self->config, "core", "mode", "bare",
+                                            &remote_mode_str, error))
+      return FALSE;
+    g_variant_dict_insert_value (&additional_metadata_builder, OSTREE_SUMMARY_MODE,
+                                 g_variant_new_string (remote_mode_str));
+  }
+
+  {
+    gboolean tombstone_commits = FALSE;
+    if (!ot_keyfile_get_boolean_with_default (self->config, "core", "tombstone-commits", FALSE,
+                                              &tombstone_commits, error))
+      return FALSE;
+    g_variant_dict_insert_value (&additional_metadata_builder, OSTREE_SUMMARY_TOMBSTONE_COMMITS,
+                                 g_variant_new_boolean (tombstone_commits));
+  }
+
   /* Add refs which have a collection specified, which could be in refs/mirrors,
    * refs/heads, and/or refs/remotes. */
   {
index 225d1845858085faa8da562ec415f7a58423e031..1f911d4ef9d61b8c4fa3ed55635b12be8adb6fe7 100644 (file)
@@ -361,6 +361,22 @@ ot_dump_summary_bytes (GBytes          *summary_bytes,
           pretty_key = "Collection Map";
           value_str = g_strdup ("(printed above)");
         }
+      else if (g_strcmp0 (key, OSTREE_SUMMARY_MODE) == 0)
+        {
+          OstreeRepoMode repo_mode;
+          const char *repo_mode_str = g_variant_get_string (value, NULL);
+
+          pretty_key = "Repository Mode";
+          if (!ostree_repo_mode_from_string (repo_mode_str, &repo_mode, NULL))
+            value_str = g_strdup_printf ("Invalid (ā€˜%s’)", repo_mode_str);
+          else
+            value_str = g_strdup (repo_mode_str);
+        }
+      else if (g_strcmp0 (key, OSTREE_SUMMARY_TOMBSTONE_COMMITS) == 0)
+        {
+          pretty_key = "Has Tombstone Commits";
+          value_str = g_strdup (g_variant_get_boolean (value) ? "Yes" : "No");
+        }
       else
         {
           value_str = g_variant_print (value, FALSE);
index 14de0294c59b0aff68efdded0b50574abdb23e4b..f6278a8586772d2dfa57ffbe956c28523211a7e8 100755 (executable)
@@ -64,5 +64,5 @@ echo "ok view summary"
 ${OSTREE} summary --raw > raw-summary.txt
 assert_file_has_content_literal raw-summary.txt "('main', ("
 assert_file_has_content_literal raw-summary.txt "('other', ("
-assert_file_has_content_literal raw-summary.txt "{'ostree.summary.last-modified': <uint64"
+assert_file_has_content_literal raw-summary.txt "'ostree.summary.last-modified': <uint64"
 echo "ok view summary raw"